<!DOCTYPE html>
<html lang="en">
  <head>
    <title>GroupedObservable Structure Reference</title>
    <link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="../css/highlight.css" />
    <meta charset="utf-8">
    <script src="../js/jquery.min.js" defer></script>
    <script src="../js/jazzy.js" defer></script>

    <script src="../js/lunr.min.js" defer></script>
    <script src="../js/typeahead.jquery.js" defer></script>
    <script src="../js/jazzy.search.js" defer></script>
  </head>
  <body>

    <a name="//apple_ref/swift/Struct/GroupedObservable" class="dashAnchor"></a>

    <a title="GroupedObservable Structure Reference"></a>

    <header class="header">
      <p class="header-col header-col--primary">
        <a class="header-link" href="../index.html">
          RxSwift 6.9.0 Docs
        </a>
         (95% documented)
      </p>

      <div class="header-col--secondary">
        <form role="search" action="../search.json">
          <input type="text" placeholder="Search documentation" data-typeahead>
        </form>
      </div>

        <p class="header-col header-col--secondary">
          <a class="header-link" href="https://github.com/ReactiveX/RxSwift">
            <img class="header-icon" src="../img/gh.png" alt="GitHub"/>
            View on GitHub
          </a>
        </p>

    </header>

    <p class="breadcrumbs">
      <a class="breadcrumb" href="../index.html">RxSwift Reference</a>
      <img class="carat" src="../img/carat.png" alt=""/>
      GroupedObservable Structure Reference
    </p>

    <div class="content-wrapper">
      <nav class="navigation">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../RxSwift.html">RxSwift</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Structs/AnyObserver.html">AnyObserver</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Structs/Binder.html">Binder</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/Cancelable.html">Cancelable</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/ConnectableObservableType.html">ConnectableObservableType</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/Disposable.html">Disposable</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Enums/Event.html">Event</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Structs/GroupedObservable.html">GroupedObservable</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/ImmediateSchedulerType.html">ImmediateSchedulerType</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/Observable.html">Observable</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/ObservableConvertibleType.html">ObservableConvertibleType</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/ObservableType.html">ObservableType</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/ObserverType.html">ObserverType</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Structs/Reactive.html">Reactive</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/SchedulerType.html">SchedulerType</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../RxSwift%2FDisposables.html">RxSwift/Disposables</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/BooleanDisposable.html">BooleanDisposable</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/CompositeDisposable.html">CompositeDisposable</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/CompositeDisposable.html#/s:7RxSwift19CompositeDisposableC10DisposeKeyV">– DisposeKey</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Structs/Disposables.html">Disposables</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/DisposeBag.html">DisposeBag</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/DisposeBag/DisposableBuilder.html">– DisposableBuilder</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/DisposeBag/DisposableBuilder.html">– DisposableBuilder</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../RxSwift%2FDisposables.html#/s:7RxSwift11DisposeBaseC">DisposeBase</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/RefCountDisposable.html">RefCountDisposable</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/ScheduledDisposable.html">ScheduledDisposable</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/SerialDisposable.html">SerialDisposable</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/SingleAssignmentDisposable.html">SingleAssignmentDisposable</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../RxSwift%2FSchedulers.html">RxSwift/Schedulers</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/ConcurrentDispatchQueueScheduler.html">ConcurrentDispatchQueueScheduler</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/ConcurrentMainScheduler.html">ConcurrentMainScheduler</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/CurrentThreadScheduler.html">CurrentThreadScheduler</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/HistoricalScheduler.html">HistoricalScheduler</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Structs/HistoricalSchedulerTimeConverter.html">HistoricalSchedulerTimeConverter</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/MainScheduler.html">MainScheduler</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/OperationQueueScheduler.html">OperationQueueScheduler</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/SerialDispatchQueueScheduler.html">SerialDispatchQueueScheduler</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/VirtualTimeConverterType.html">VirtualTimeConverterType</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/VirtualTimeScheduler.html">VirtualTimeScheduler</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../RxSwift%2FSubjects.html">RxSwift/Subjects</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/AsyncSubject.html">AsyncSubject</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/BehaviorSubject.html">BehaviorSubject</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/PublishSubject.html">PublishSubject</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/ReplaySubject.html">ReplaySubject</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/SubjectType.html">SubjectType</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../RxSwift%2FTraits%2FInfallible.html">RxSwift/Traits/Infallible</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Structs/Infallible.html">Infallible</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../RxSwift%2FTraits%2FPrimitiveSequence.html">RxSwift/Traits/PrimitiveSequence</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../RxSwift%2FTraits%2FPrimitiveSequence.html#/s:7RxSwift11Completablea">Completable</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../RxSwift%2FTraits%2FPrimitiveSequence.html#/s:7RxSwift5Maybea">Maybe</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Structs/PrimitiveSequence.html">PrimitiveSequence</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../RxSwift%2FTraits%2FPrimitiveSequence.html#/s:7RxSwift6Singlea">Single</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../Other%20Classes.html">Other Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Classes/ConnectableObservable.html">ConnectableObservable</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../Other%20Global%20Variables.html">Other Global Variables</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Other%20Global%20Variables.html#/s:7RxSwift29maxTailRecursiveSinkStackSizeSivp">maxTailRecursiveSinkStackSize</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../Other%20Enums.html">Other Enumerations</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Enums/CompletableEvent.html">CompletableEvent</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Other%20Enums.html#/s:7RxSwift16CompletableTraitO">CompletableTrait</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Enums/Hooks.html">Hooks</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Enums/InfallibleEvent.html">InfallibleEvent</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Enums/MaybeEvent.html">MaybeEvent</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Other%20Enums.html#/s:7RxSwift10MaybeTraitO">MaybeTrait</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Enums/RxError.html">RxError</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Other%20Enums.html#/s:7RxSwift11SingleTraitO">SingleTrait</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Enums/SubjectLifetimeScope.html">SubjectLifetimeScope</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Enums/TakeBehavior.html">TakeBehavior</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Enums/VirtualTimeComparison.html">VirtualTimeComparison</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../Other%20Extensions.html">Other Extensions</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Extensions/AsyncSequence.html">AsyncSequence</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Other%20Extensions.html#/s:10Foundation11JSONDecoderC">JSONDecoder</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Other%20Extensions.html#/c:objc(cs)NSObject">NSObject</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Other%20Extensions.html#/s:10Foundation19PropertyListDecoderC">PropertyListDecoder</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../Other%20Protocols.html">Other Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/DataDecoder.html">DataDecoder</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/EventConvertible.html">EventConvertible</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/InfallibleType.html">InfallibleType</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/PrimitiveSequenceType.html">PrimitiveSequenceType</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Protocols/ReactiveCompatible.html">ReactiveCompatible</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../Other%20Structs.html">Other Structures</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Structs/Resources.html">Resources</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="../Other%20Typealiases.html">Other Type Aliases</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Other%20Typealiases.html#/s:7RxSwift0A15AbstractIntegera">RxAbstractInteger</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Other%20Typealiases.html#/s:7RxSwift0A10Observablea">RxObservable</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Other%20Typealiases.html#/s:7RxSwift0A4Timea">RxTime</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Other%20Typealiases.html#/s:7RxSwift0A12TimeIntervala">RxTimeInterval</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="../Other%20Typealiases.html#/s:7RxSwift11SingleEventa">SingleEvent</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">

        <section class="section">
          <div class="section-content top-matter">
            <h1>GroupedObservable</h1>
              <div class="declaration">
                <div class="language">

                  <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">struct</span> <span class="kt">GroupedObservable</span><span class="o">&lt;</span><span class="kt">Key</span><span class="p">,</span> <span class="kt">Element</span><span class="o">&gt;</span> <span class="p">:</span> <span class="kt"><a href="../Protocols/ObservableType.html">ObservableType</a></span></code></pre>

                </div>
              </div>
            <p>Represents an observable sequence of elements that share a common key.
<code>GroupedObservable</code> is typically created by the <code>groupBy</code> operator.
Each <code>GroupedObservable</code> instance represents a collection of elements
that are grouped by a specific key.</p>

<p>Example usage:</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">observable</span> <span class="o">=</span> <span class="kt">Observable</span><span class="o">.</span><span class="nf">of</span><span class="p">(</span><span class="s">"Apple"</span><span class="p">,</span> <span class="s">"Banana"</span><span class="p">,</span> <span class="s">"Apricot"</span><span class="p">,</span> <span class="s">"Blueberry"</span><span class="p">,</span> <span class="s">"Avocado"</span><span class="p">)</span>

<span class="k">let</span> <span class="nv">grouped</span> <span class="o">=</span> <span class="n">observable</span><span class="o">.</span><span class="n">groupBy</span> <span class="p">{</span> <span class="n">fruit</span> <span class="k">in</span>
    <span class="n">fruit</span><span class="o">.</span><span class="n">first</span><span class="o">!</span> <span class="c1">// Grouping by the first letter of each fruit</span>
<span class="p">}</span>

<span class="n">_</span> <span class="o">=</span> <span class="n">grouped</span><span class="o">.</span><span class="n">subscribe</span> <span class="p">{</span> <span class="n">group</span> <span class="k">in</span>
    <span class="nf">print</span><span class="p">(</span><span class="s">"Group: </span><span class="se">\(</span><span class="n">group</span><span class="o">.</span><span class="n">key</span><span class="se">)</span><span class="s">"</span><span class="p">)</span>
    <span class="n">_</span> <span class="o">=</span> <span class="n">group</span><span class="o">.</span><span class="n">subscribe</span> <span class="p">{</span> <span class="n">event</span> <span class="k">in</span>
        <span class="nf">print</span><span class="p">(</span><span class="n">event</span><span class="p">)</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre>

<p>This will print:</p>
<pre class="highlight swift"><code><span class="kt">Group</span><span class="p">:</span> <span class="kt">A</span>
<span class="nf">next</span><span class="p">(</span><span class="kt">Apple</span><span class="p">)</span>
<span class="nf">next</span><span class="p">(</span><span class="kt">Apricot</span><span class="p">)</span>
<span class="nf">next</span><span class="p">(</span><span class="kt">Avocado</span><span class="p">)</span>
<span class="kt">Group</span><span class="p">:</span> <span class="kt">B</span>
<span class="nf">next</span><span class="p">(</span><span class="kt">Banana</span><span class="p">)</span>
<span class="nf">next</span><span class="p">(</span><span class="kt">Blueberry</span><span class="p">)</span>
</code></pre>

          </div>
        </section>

        <section class="section">
          <div class="section-content">
            <div class="task-group">
              <ul class="item-container">
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:7RxSwift17GroupedObservableV3keyxvp"></a>
                    <a name="//apple_ref/swift/Property/key" class="dashAnchor"></a>
                    <a class="token" href="#/s:7RxSwift17GroupedObservableV3keyxvp">key</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>The key associated with this grouped observable sequence.
All elements emitted by this observable share this common key.</p>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="k">let</span> <span class="nv">key</span><span class="p">:</span> <span class="kt">Key</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:7RxSwift17GroupedObservableV3key6sourceACyxq_Gx_AA0D0Cyq_Gtcfc"></a>
                    <a name="//apple_ref/swift/Method/init(key:source:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:7RxSwift17GroupedObservableV3key6sourceACyxq_Gx_AA0D0Cyq_Gtcfc">init(key:<wbr>source:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Initializes a grouped observable sequence with a key and a source observable sequence.</p>

<p>Example usage:</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">sourceObservable</span> <span class="o">=</span> <span class="kt">Observable</span><span class="o">.</span><span class="nf">of</span><span class="p">(</span><span class="s">"Apple"</span><span class="p">,</span> <span class="s">"Apricot"</span><span class="p">,</span> <span class="s">"Avocado"</span><span class="p">)</span>
<span class="k">let</span> <span class="nv">groupedObservable</span> <span class="o">=</span> <span class="kt">GroupedObservable</span><span class="p">(</span><span class="nv">key</span><span class="p">:</span> <span class="s">"A"</span><span class="p">,</span> <span class="nv">source</span><span class="p">:</span> <span class="n">sourceObservable</span><span class="p">)</span>

<span class="n">_</span> <span class="o">=</span> <span class="n">groupedObservable</span><span class="o">.</span><span class="n">subscribe</span> <span class="p">{</span> <span class="n">event</span> <span class="k">in</span>
    <span class="nf">print</span><span class="p">(</span><span class="n">event</span><span class="p">)</span>
<span class="p">}</span>
</code></pre>

<p>This will print:</p>
<pre class="highlight swift"><code><span class="nf">next</span><span class="p">(</span><span class="kt">Apple</span><span class="p">)</span>
<span class="nf">next</span><span class="p">(</span><span class="kt">Apricot</span><span class="p">)</span>
<span class="nf">next</span><span class="p">(</span><span class="kt">Avocado</span><span class="p">)</span>
</code></pre>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="nf">init</span><span class="p">(</span><span class="nv">key</span><span class="p">:</span> <span class="kt">Key</span><span class="p">,</span> <span class="nv">source</span><span class="p">:</span> <span class="kt"><a href="../Classes/Observable.html">Observable</a></span><span class="o">&lt;</span><span class="kt">Element</span><span class="o">&gt;</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>key</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The key associated with this grouped observable sequence.</p>
                                </div>
                              </td>
                            </tr>
                            <tr>
                              <td>
                                <code>
                                <em>source</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The observable sequence of elements for the specified key.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:7RxSwift17GroupedObservableV9subscribeyAA10Disposable_pqd__7ElementQyd__Rs_AA12ObserverTypeRd__lF"></a>
                    <a name="//apple_ref/swift/Method/subscribe(_:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:7RxSwift17GroupedObservableV9subscribeyAA10Disposable_pqd__7ElementQyd__Rs_AA12ObserverTypeRd__lF">subscribe(_:<wbr>)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Subscribes an observer to receive events emitted by the source observable sequence.</p>

<p>Example usage:</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">fruitsObservable</span> <span class="o">=</span> <span class="kt">Observable</span><span class="o">.</span><span class="nf">of</span><span class="p">(</span><span class="s">"Apple"</span><span class="p">,</span> <span class="s">"Banana"</span><span class="p">,</span> <span class="s">"Apricot"</span><span class="p">,</span> <span class="s">"Blueberry"</span><span class="p">,</span> <span class="s">"Avocado"</span><span class="p">)</span>
<span class="k">let</span> <span class="nv">grouped</span> <span class="o">=</span> <span class="n">fruitsObservable</span><span class="o">.</span><span class="n">groupBy</span> <span class="p">{</span> <span class="nv">$0</span><span class="o">.</span><span class="n">first</span><span class="o">!</span> <span class="p">}</span> <span class="c1">// Group by first letter</span>

<span class="n">_</span> <span class="o">=</span> <span class="n">grouped</span><span class="o">.</span><span class="n">subscribe</span> <span class="p">{</span> <span class="n">group</span> <span class="k">in</span>
    <span class="k">if</span> <span class="n">group</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">"A"</span> <span class="p">{</span>
        <span class="n">_</span> <span class="o">=</span> <span class="n">group</span><span class="o">.</span><span class="n">subscribe</span> <span class="p">{</span> <span class="n">event</span> <span class="k">in</span>
            <span class="nf">print</span><span class="p">(</span><span class="n">event</span><span class="p">)</span>
        <span class="p">}</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre>

<p>This will print:</p>
<pre class="highlight swift"><code><span class="nf">next</span><span class="p">(</span><span class="kt">Apple</span><span class="p">)</span>
<span class="nf">next</span><span class="p">(</span><span class="kt">Apricot</span><span class="p">)</span>
<span class="nf">next</span><span class="p">(</span><span class="kt">Avocado</span><span class="p">)</span>
</code></pre>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="n">subscribe</span><span class="o">&lt;</span><span class="kt">Observer</span><span class="o">&gt;</span><span class="p">(</span><span class="n">_</span> <span class="nv">observer</span><span class="p">:</span> <span class="kt">Observer</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt"><a href="../Protocols/Disposable.html">Disposable</a></span> <span class="k">where</span> <span class="kt">Element</span> <span class="o">==</span> <span class="kt">Observer</span><span class="o">.</span><span class="kt">Element</span><span class="p">,</span> <span class="kt">Observer</span> <span class="p">:</span> <span class="kt"><a href="../Protocols/ObserverType.html">ObserverType</a></span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>observer</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The observer that will receive the events of the source observable.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>A <code><a href="../Protocols/Disposable.html">Disposable</a></code> representing the subscription, which can be used to cancel the subscription.</p>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:7RxSwift17GroupedObservableV02asD0AA0D0Cyq_GyF"></a>
                    <a name="//apple_ref/swift/Method/asObservable()" class="dashAnchor"></a>
                    <a class="token" href="#/s:7RxSwift17GroupedObservableV02asD0AA0D0Cyq_GyF">asObservable()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Converts this <code>GroupedObservable</code> into a regular <code><a href="../Classes/Observable.html">Observable</a></code> sequence.
This allows you to work with the sequence without directly interacting with the key.</p>

<p>Example usage:</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">fruitsObservable</span> <span class="o">=</span> <span class="kt">Observable</span><span class="o">.</span><span class="nf">of</span><span class="p">(</span><span class="s">"Apple"</span><span class="p">,</span> <span class="s">"Banana"</span><span class="p">,</span> <span class="s">"Apricot"</span><span class="p">,</span> <span class="s">"Blueberry"</span><span class="p">,</span> <span class="s">"Avocado"</span><span class="p">)</span>
<span class="k">let</span> <span class="nv">grouped</span> <span class="o">=</span> <span class="n">fruitsObservable</span><span class="o">.</span><span class="n">groupBy</span> <span class="p">{</span> <span class="nv">$0</span><span class="o">.</span><span class="n">first</span><span class="o">!</span> <span class="p">}</span> <span class="c1">// Group by first letter</span>

<span class="n">_</span> <span class="o">=</span> <span class="n">grouped</span><span class="o">.</span><span class="n">subscribe</span> <span class="p">{</span> <span class="n">group</span> <span class="k">in</span>
    <span class="k">if</span> <span class="n">group</span><span class="o">.</span><span class="n">key</span> <span class="o">==</span> <span class="s">"A"</span> <span class="p">{</span>
        <span class="k">let</span> <span class="nv">regularObservable</span> <span class="o">=</span> <span class="n">group</span><span class="o">.</span><span class="nf">asObservable</span><span class="p">()</span>
        <span class="n">_</span> <span class="o">=</span> <span class="n">regularObservable</span><span class="o">.</span><span class="n">subscribe</span> <span class="p">{</span> <span class="n">event</span> <span class="k">in</span>
            <span class="nf">print</span><span class="p">(</span><span class="n">event</span><span class="p">)</span>
        <span class="p">}</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre>

<p>This will print:</p>
<pre class="highlight swift"><code><span class="nf">next</span><span class="p">(</span><span class="kt">Apple</span><span class="p">)</span>
<span class="nf">next</span><span class="p">(</span><span class="kt">Apricot</span><span class="p">)</span>
<span class="nf">next</span><span class="p">(</span><span class="kt">Avocado</span><span class="p">)</span>
</code></pre>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">asObservable</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt"><a href="../Classes/Observable.html">Observable</a></span><span class="o">&lt;</span><span class="kt">Element</span><span class="o">&gt;</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>The underlying <code><a href="../Classes/Observable.html">Observable</a></code> sequence of elements for the specified key.</p>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
          </div>
        </section>

      </article>
    </div>
    <section class="footer">
      <p>&copy; 2024 <a class="link" href="https://github.com/ReactiveX/RxSwift" target="_blank" rel="external noopener">Shai Mishali and Krunoslav Zaher</a>. All rights reserved. (Last updated: 2024-10-06)</p>
      <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.4</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
    </section>
  </body>
</html>
